// Created by Marcus Kammer | digital media artist

package SketchPackage;

import processing.core.PApplet;
import fullscreen.*;

public class Sketch extends PApplet
{
  int w = screen.width;
  int h = screen.height;

  int mWidth = 20;
  int mHeight = mWidth;

  int xAxis = w / mWidth;
  int yAxis = h / mHeight;

  SoftFullScreen fs;

  Cell[][] rect = new Cell[ yAxis ][ xAxis ];

  public void LEDMatrix()
  {
    for( int i = 0; i < yAxis; i++ )
    {
      for( int j = 0; j < xAxis; j++ )
      {
        rect[i][j] = new Cell( this );

        rect[i][j].mWidth = mWidth;
        rect[i][j].mHeight = mHeight;

        if( j == 0 )
        {
          rect[i][j].mPosX = 0;
        } else
        {
          rect[i][j].mPosX += rect[i][j - 1].mPosX += rect[i][j - 1].mWidth;
        }

        if( i == 0 )
        {
          rect[i][j].mPosY = 0;
        } else
        {
          rect[i][j].mPosY += rect[i - 1][j].mPosY += rect[i - 1][j].mHeight;
        }

        System.out.println( i + " " + j + " " + rect[i][j].mPosX + " "
            + rect[i][j].mPosY );

        rect[i][j].mDraw(
            255,
            255,
            255,
            rect[i][j].mPosX,
            rect[i][j].mPosY,
            rect[i][j].mWidth,
            rect[i][j].mHeight );
      }
    }
  }

  public void setup()
  {
    size( w, h );
    fs = new SoftFullScreen( this );
    fs.enter();
    rectMode( CORNER );
    frameRate( 30 );
    smooth();
    stroke( 180, 180, 180 );
    background( 0 );
    LEDMatrix();
  }

  public void draw()
  {
    int r = ( int ) random( yAxis );
    int i = ( int ) random( xAxis );

    rect[r][i].mDraw(
        random( 255 ),
        random( 255 ),
        random( 255 ),
        rect[r][i].mPosX,
        rect[r][i].mPosY,
        rect[r][i].mWidth,
        rect[r][i].mHeight );
  }

  public static void main(String _args[])
  {
    PApplet.main( new String[]
    { SketchPackage.Sketch.class.getName() } );
  }
}